import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore();

export const columns: BasicColumn[] = [
  {
    title: '部门名称',
    dataIndex: 'name',
    width: 160,
    align: 'left',
  },
  {
    title: '排序',
    dataIndex: 'orderNo',
    width: 50,
  },
  {
    title: '是否通过',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      const status = record.status;
      const enable = ~~status === 0;
      const color = enable ? 'green' : 'red';
      const text = enable ? '启用' : '停用';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '原因',
    dataIndex: 'descr',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'text',
    label: '部门名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'status',
    label: '是否通过',
    component: 'Select',
    componentProps: {
      options: [
        { label: '启用', value: 0 },
        { label: '停用', value: 1 },
      ],
    },
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'pczt',
    label: '消防排查状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '无需排查', value: 3 },
        //{ label: '已排查', value: 2 },
        { label: '排查中', value: 1 },
        { label: '未排查', value: 0 },
      ],
      placeholder: '请选择',
    },
    labelWidth: '8em',
  },
];
// 消防--隐患排查--场所安全排查-- 编辑弹框 -- 消防状态
export function getFormSchema(): FormSchema[] {
  const pcztXXX: FormSchema[] = [];
  if (['FireControl', 'Admin'].includes(userStore.getUserGroup)) {
    pcztXXX.push({
      field: 'pcztFire',
      label: '消防排查状态',
      component: 'Select',
      componentProps: {
        options: [
          { label: '无需排查', value: 3 },
          { label: '已排查(自动计算状态)', value: 2 },
          //{ label: '排查中', value: 1 },
          // { label: '已排查无隐患', value: 20 },
          // { label: '已排查有隐患', value: 21 },
          { label: '未排查', value: 0 },
        ],
        placeholder: '请选择',
      },
      labelWidth: '8em',
    });
  }
  return pcztXXX;
}
